package String;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-07-11
 * Time: 7:36
 */
public class Test {
    public static void main(String[] args) {
        String s1 = new String("world");

    }
    public static void main8(String[] args) {
        String s1 = "hello";
        String s2 = "hello";
        String s3 = new String("hello");
        String s4 = new String("hello");
        System.out.println(s1==s2);//true
        System.out.println(s1==s3);//false
        System.out.println(s3==s4);//false
    }
    public static void main7(String[] args) {
        String s1 = "abcd";
        String s2 = "ABCd";
        String s3 = "ACbd";
        System.out.println(s1.compareToIgnoreCase(s2));//s1.length()-s2.length() = 5-4==1
        System.out.println(s1.compareToIgnoreCase(s3));//'b'-'c' == 1
    }
    public static void main6(String[] args) {
        String s1 = "hello";
        String s2 = "HELLO";
        System.out.println(s1.equalsIgnoreCase(s2));//true
    }
    public static void main5(String[] args) {
        String s1 = "abcde";
        String s2 = "abcd";
        String s3 = "acbde";
        System.out.println(s1.compareTo(s2));//s1.length()-s2.length() = 5-4==1
        System.out.println(s1.compareTo(s3));//'b'-'c' == 1
    }
    public static void main4(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("world");
        System.out.println(s1.equalsIgnoreCase(s2));//true
        System.out.println(s1.equals(s3));//false
    }
    public static void main3(String[] args) {
        int a = 10;
        int b = 20;
        int c = 10;
        System.out.println(a==b);//false
        System.out.println(a==c);//true
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;
        System.out.println(s1==s2);//false
        System.out.println(s1==s3);//true
    }
    public static void main2(String[] args) {
        //s0、s1和s2都分别new了一个对象，所以这三个引用引用的不是同一个对象,尽管s0和s1对象的内容相同
        //s3和s0是同一个对象的引用
        String s0 = new String("123");
        String s1 = new String("123");
        String s2 = new String("234");
        String s3 = s0;
        System.out.println(s0.length());//获取字符串的长度：3
        System.out.println(s0.isEmpty());//如果字符串的长度为0，返回true，否则返回false
    }
    public static void main1(String[] args) {
        //使用常量串构造
        String s1= "123";
        System.out.println(s1);
        //直接new对象构造
        String s2 = new String("456");
        System.out.println(s2);
        //通过字符数组进行构造
        char[] chars = new char[]{'7','8','9'};
        System.out.println(chars.length);
        String s3 = new String(chars);
        System.out.println(s3);
    }


}
